package com.xuantian.baoming.controller;

import com.wechat.pay.contrib.apache.httpclient.auth.Verifier;
import com.xuantian.baoming.entity.OrderInfo;
import com.xuantian.baoming.service.WxH5Service;
import com.xuantian.baoming.service.WxPayService;
import com.xuantian.baoming.vo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@CrossOrigin //开放前端的跨域访问
@RestController
@RequestMapping("/api/wx-h5")
@Slf4j
public class WxH5Controller {
    @Resource
    private WxPayService wxPayService;
    @Resource
    private Verifier verifier;
    @Resource
    private WxH5Service wxH5Service;

    //h5支付下单
    @PostMapping("/h5")
    public R nativePay(HttpServletRequest request,@RequestBody OrderInfo orderInfo1){

        log.info("发起支付请求 H5下单");

        Map<String,Object> map = null;
        try {
            map = wxH5Service.h5Pay(request,orderInfo1);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return R.ok(map);
    }

    /**
     * h5回调支付通知
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/h5/notify")
    public String h5Notify(HttpServletRequest request, HttpServletResponse response){


        return null;
    }

}
